<template>
  <view class="user-header-enhanced">
    <!-- 装饰性背景 -->
    <view class="header-bg-decoration"></view>
    <view class="header-glow"></view>
    
    <view class="header-content">
      <view class="avatar-section-enhanced">
        <view class="avatar-outer-ring"></view>
        <view class="avatar-container-enhanced" @click="handleAvatarClick">
          <image 
            v-if="userInfo.avatar && isLoggedIn" 
            :src="userInfo.avatar" 
            class="user-avatar-enhanced"
            mode="aspectFill"
            @error="handleAvatarError"
          />
          <view v-else class="default-avatar-enhanced" :class="{ 'login-prompt': !isLoggedIn }">
            <text class="avatar-text-large">{{ isLoggedIn ? (userInfo.name ? userInfo.name.charAt(0) : 'U') : '🔐' }}</text>
            <text v-if="!isLoggedIn" class="login-hint-new">点击登录</text>
          </view>
        </view>
        <!-- 用户等级徽章 -->
        <view v-if="isLoggedIn" class="user-level-badge">
          <text class="level-icon">⭐</text>
          <text class="level-number">{{ userLevel }}</text>
        </view>
      </view>
      
      <view class="user-info-enhanced">
        <view class="user-name-row-new">
          <text class="user-name-new">{{ isLoggedIn ? (userInfo.name || '未设置') : '未登录' }}</text>
          <view v-if="isLoggedIn" class="role-badge-new" :class="getRoleClass(userInfo.role)">
            <text class="role-icon">{{ userInfo.role === 'admin' ? '👑' : '👤' }}</text>
            <text class="role-text-new">{{ getRoleText(userInfo.role) }}</text>
          </view>
        </view>
        <text class="user-email-new">{{ isLoggedIn ? (userInfo.email || '未设置邮箱') : '请先登录账户' }}</text>
        <text class="user-id-new">ID: {{ isLoggedIn ? (userInfo.id || 'N/A') : 'N/A' }}</text>
        
        <!-- 积分进度条 - 增强版 -->
        <view class="points-section-new">
          <view class="points-header">
            <view class="points-left">
              <text class="points-icon-new">💎</text>
              <text class="points-amount">{{ userPoints }}</text>
              <text class="points-label">积分</text>
            </view>
            <text class="level-progress-text">{{ levelProgress }}% → Lv.{{ userLevel + 1 }}</text>
          </view>
          <view class="progress-bar-container">
            <view class="progress-bar-bg"></view>
            <view class="progress-bar-fill" :style="{ width: levelProgress + '%' }">
              <view class="progress-shine"></view>
            </view>
          </view>
        </view>
      </view>
      
      <!-- 设置按钮 - 优化版 -->
      <view class="settings-btn-new" @click="navigateToSettings">
        <text class="settings-icon-new">⚙️</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'ProfileHeader',
  props: {
    userInfo: {
      type: Object,
      required: true
    },
    isLoggedIn: {
      type: Boolean,
      default: false
    },
    userPoints: {
      type: Number,
      default: 0
    },
    userLevel: {
      type: Number,
      default: 1
    },
    levelProgress: {
      type: Number,
      default: 0
    }
  },
  methods: {
    handleAvatarClick() {
      this.$emit('avatar-click')
    },
    handleAvatarError() {
      this.$emit('avatar-error')
    },
    navigateToSettings() {
      this.$emit('settings-click')
    },
    getRoleText(role) {
      return role === 'admin' ? '管理员' : '普通用户'
    },
    getRoleClass(role) {
      return role === 'admin' ? 'role-admin' : 'role-user'
    }
  }
}
</script>

<style scoped>
/* ========== 用户头部卡片 - 增强版 ========== */
.user-header-enhanced {
  position: relative;
  background: white;
  border-radius: 28rpx;
  padding: 36rpx 28rpx;
  margin-bottom: 24rpx;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.header-bg-decoration {
  position: absolute;
  top: -60rpx;
  right: -60rpx;
  width: 240rpx;
  height: 240rpx;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
  border-radius: 50%;
}

.header-glow {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120rpx;
  background: linear-gradient(180deg, transparent 0%, rgba(102, 126, 234, 0.03) 100%);
}

.header-content {
  position: relative;
  display: flex;
  align-items: center;
  gap: 20rpx;
  z-index: 1;
}

.avatar-section-enhanced {
  position: relative;
}

.avatar-outer-ring {
  position: absolute;
  top: -8rpx;
  left: -8rpx;
  right: -8rpx;
  bottom: -8rpx;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  opacity: 0.15;
  animation: ring-pulse 3s ease-in-out infinite;
}

@keyframes ring-pulse {
  0%, 100% { transform: scale(1); opacity: 0.15; }
  50% { transform: scale(1.08); opacity: 0.25; }
}

.avatar-container-enhanced {
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  overflow: hidden;
  border: 5rpx solid white;
  box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.12);
  position: relative;
  z-index: 1;
}

.user-avatar-enhanced {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.default-avatar-enhanced {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.default-avatar-enhanced.login-prompt {
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
  animation: pulse-login 2s ease-in-out infinite;
}

@keyframes pulse-login {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.avatar-text-large {
  color: white;
  font-size: 48rpx;
  font-weight: bold;
  margin-bottom: 6rpx;
}

.login-hint-new {
  color: white;
  font-size: 20rpx;
  font-weight: 500;
  opacity: 0.95;
}

.user-level-badge {
  position: absolute;
  bottom: -8rpx;
  right: -8rpx;
  background: linear-gradient(135deg, #ffd700 0%, #ffb300 100%);
  padding: 6rpx 12rpx;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 12rpx rgba(255, 193, 7, 0.4);
  display: flex;
  align-items: center;
  gap: 4rpx;
  z-index: 2;
  animation: badge-shine 3s ease-in-out infinite;
}

@keyframes badge-shine {
  0%, 100% { box-shadow: 0 4rpx 12rpx rgba(255, 193, 7, 0.4); }
  50% { box-shadow: 0 6rpx 16rpx rgba(255, 193, 7, 0.6); }
}

.level-icon {
  font-size: 16rpx;
}

.level-number {
  color: white;
  font-size: 20rpx;
  font-weight: bold;
}

.user-info-enhanced {
  flex: 1;
}

.user-name-row-new {
  display: flex;
  align-items: center;
  gap: 10rpx;
  margin-bottom: 8rpx;
}

.user-name-new {
  font-size: 34rpx;
  font-weight: bold;
  color: #1f2937;
  letter-spacing: 0.5rpx;
}

.role-badge-new {
  display: flex;
  align-items: center;
  gap: 4rpx;
  padding: 6rpx 12rpx;
  border-radius: 14rpx;
  font-size: 20rpx;
}

.role-badge-new.role-admin {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 1rpx solid #fbbf24;
}

.role-badge-new.role-user {
  background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
  border: 1rpx solid #818cf8;
}

.role-icon {
  font-size: 18rpx;
}

.role-text-new {
  font-weight: bold;
  color: #d97706;
}

.role-badge-new.role-user .role-text-new {
  color: #4f46e5;
}

.user-email-new {
  display: block;
  font-size: 24rpx;
  color: #6b7280;
  margin-bottom: 6rpx;
}

.user-id-new {
  display: block;
  font-size: 20rpx;
  color: #9ca3af;
  margin-bottom: 16rpx;
}

/* 积分部分 - 全新设计 */
.points-section-new {
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  border-radius: 14rpx;
  padding: 14rpx 16rpx;
  margin-top: 12rpx;
}

.points-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10rpx;
}

.points-left {
  display: flex;
  align-items: center;
  gap: 8rpx;
}

.points-icon-new {
  font-size: 28rpx;
  filter: drop-shadow(0 2rpx 4rpx rgba(0, 0, 0, 0.1));
}

.points-amount {
  font-size: 32rpx;
  font-weight: bold;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.points-label {
  font-size: 22rpx;
  color: #6b7280;
}

.level-progress-text {
  font-size: 20rpx;
  color: #9ca3af;
  font-weight: 500;
}

.progress-bar-container {
  position: relative;
  height: 12rpx;
  border-radius: 6rpx;
  overflow: hidden;
}

.progress-bar-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #d1d5db;
}

.progress-bar-fill {
  position: relative;
  height: 100%;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  border-radius: 6rpx;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.progress-shine {
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, 
    transparent 0%, 
    rgba(255, 255, 255, 0.4) 50%, 
    transparent 100%);
  animation: shine 2s ease-in-out infinite;
}

@keyframes shine {
  0% { left: -100%; }
  100% { left: 200%; }
}

.settings-btn-new {
  width: 68rpx;
  height: 68rpx;
  border-radius: 50%;
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
  transition: all 0.3s ease;
}

.settings-btn-new:active {
  transform: scale(0.92);
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
}

.settings-icon-new {
  font-size: 30rpx;
}
</style>

